package com.hspedu.set_;

@SuppressWarnings({"all"})
public class HashSetStructure {
    public static void main(String[] args) {
        // 模拟一个 HashSet 的底层 (HashMap 的底层结果)
        //1. 创建一个数组，数组类型是 Node[]
        //2. 有些人直接把 Node[] 称为 表
        Node[] table = new Node[16];
        System.out.println("table=" + table);
        //3.创建节点
        Node john = new Node("john", null);
        table[2] = john;
        Node jack = new Node("jack", null);
        john.next = jack;// 将 jack 结点挂载到 john
        Node rose = new Node("rose", null);
        jack.next = rose;// 将 rose 结点挂载到 jack

        Node lucy = new Node("lucy", null);
        table[3] = lucy;
        System.out.println("table=" + table);
    }
}

class Node {// 结点，存储数据，可以指向下一个结点，从而形成链表
    Object item;// 存放数据
    Node next;// 指向下一个结点

    public Node(Object item, Node next) {
        this.item = item;
        this.next = next;
    }

    public Object getItem() {
        return item;
    }

    public void setItem(Object item) {
        this.item = item;
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node next) {
        this.next = next;
    }
}